package com.byd.bcqw

import android.util.Log
import androidx.lifecycle.ViewModel

private const val TAG = "QuizViewModel"

class QuizViewModel : ViewModel() {
    init {
        Log.d(TAG, "ViewModel instance created")
    }

    override fun onCleared() {
        super.onCleared()
        Log.d(TAG, "ViewModel instance destroyed")
    }

    private val questionBank = listOf(
        Question(R.string.question_africa, true),
        Question(R.string.question_americas, true),
        Question(R.string.question_asia, false),
        Question(R.string.question_australia, false),
        Question(R.string.question_mideast, true),
        Question(R.string.question_oceans, true)
    )

    var currentIndex = 0
    var isCheater = false

    val currentQuestionAnswer: Boolean get() = questionBank[currentIndex].answer

    val currentQuestionText: Int get() = questionBank[currentIndex].textResId

    fun moveToNext() {
        currentIndex = if (currentIndex < questionBank.size) {
            (currentIndex + 1) % questionBank.size
        } else {
            questionBank.size
        }
    }

    fun moveToPrev() {
        currentIndex = if (currentIndex > 0) {
            (currentIndex - 1) % questionBank.size
        } else {
            0
        }
    }
}